﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using He.Web.UI;

namespace He.Web.manage.olservice
{
    public partial class group_list : Manage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                chkLoginLevel("viewolservice");
                RpgBind();
            }
        }
        #region 数据绑定
        private void RpgBind()
        {
            rptList.DataSource = new BLL.olservice_group().GetList("id>0 order by sort_id asc");
            rptList.DataBind();
        }
        #endregion

        protected void lbtnDel_Click(object sender, EventArgs e)
        {
            chkLoginLevel("delolservice");
            BLL.olservice_group bll = new BLL.olservice_group();
            for (int i = 0; i < rptList.Items.Count; i++)
            {
                CheckBox cb = (CheckBox)rptList.Items[i].FindControl("Check");
                int id = int.Parse(((HiddenField)rptList.Items[i].FindControl("HiddenId")).Value);
                if (cb.Checked)
                {
                    Model.olservice_group model = bll.GetModel(id);
                    bll.Delete(id);
                }
            }
            SaveLogs("[在线客服分组管理]批量删除");
            ShowSuccess("批量删除成功啦！", Request.RawUrl);
        }

        protected void lbtnSave_Click(object sender, EventArgs e)
        {
            chkLoginLevel("editolservice");
            BLL.olservice_group bll = new BLL.olservice_group();
            for (int i = 0; i < rptList.Items.Count; i++)
            {
                CheckBox cb = (CheckBox)rptList.Items[i].FindControl("Check");
                int id = int.Parse(((Label)rptList.Items[i].FindControl("lb_id")).Text);
                int sortId;
                if (!int.TryParse(((TextBox)rptList.Items[i].FindControl("txtSortId")).Text.Trim(), out sortId))
                {
                    sortId = 99;
                }
                bll.UpdateField(id, "sort_id=" + sortId.ToString());
            }
            SaveLogs("[在线客服管理]批量保存排序");
            ShowSuccess("排序保存成功啦！", Request.RawUrl);
        }


        //设置操作
        protected void rptList_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            chkLoginLevel("editolservice");
            int id = Convert.ToInt32(((Label)e.Item.FindControl("lb_id")).Text);
            BLL.olservice_group bll = new BLL.olservice_group();
            Model.olservice_group model = bll.GetModel(id);
            switch (e.CommandName.ToLower())
            {
                case "ibtnlock":
                    if (model.is_lock == 1)
                        bll.UpdateField(id, "is_lock=0");
                    else
                        bll.UpdateField(id, "is_lock=1");
                    break;
            }
            SaveLogs(string.Format("[在线客服分组管理]修改属性:{0}", model.group_name));
            Response.Redirect(Request.RawUrl);
        }
    }
}